package mysql

import (
	"71/appconfig"
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
)

var DB *gorm.DB
var err error

func Init() {
	// refer https://github.com/go-sql-driver/mysql#dsn-data-source-name for details
	a := appconfig.Apps.Mysql
	dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local", a.User, a.Password, a.Host, a.Port, a.Database)
	DB, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
	DB.AutoMigrate(&User{})
}
